package gui;

import java.awt.Dimension;
import java.io.File;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ui.StateObserver;
import utils.Configuration;

public class ChatStateBar extends JPanel implements StateObserver {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static ImageIcon ONLINE_ICON = new ImageIcon(Configuration.getImageFolder() + File.separator + "online.png") ;
	private static ImageIcon OFFLINE_ICON = new ImageIcon(Configuration.getImageFolder() + File.separator + "offline.png") ;
	private static String ONLINE_TEXT = "Connecté(e)" ;
	private static String OFFLINE_TEXT = "Hors Ligne" ;
	
	private JLabel iconLabel ;
	private JLabel stateLabel ;
	
	public ChatStateBar () {
		super () ;
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS)) ;
		setAlignmentX(CENTER_ALIGNMENT) ;
		this.iconLabel = new JLabel(OFFLINE_ICON) ;
		this.stateLabel = new JLabel(OFFLINE_TEXT) ;
		add(Box.createHorizontalStrut(20)) ;
		add(Box.createHorizontalGlue()) ;
		add(this.iconLabel) ;
		add(Box.createHorizontalStrut(5)) ;
		add(this.stateLabel) ;
		add(Box.createHorizontalStrut(20)) ;
		setMaximumSize(new Dimension(Short.MAX_VALUE, 20)) ;
		setMinimumSize(new Dimension(0, 20)) ;
	}
	
	@Override
	public void fireConnect() {
		this.iconLabel.setIcon(ONLINE_ICON) ;
		this.stateLabel.setText(ONLINE_TEXT) ;
	}

	@Override
	public void fireDisconnect() {
		this.iconLabel.setIcon(OFFLINE_ICON) ;
		this.stateLabel.setText(OFFLINE_TEXT) ;
	}

}
